package com.example.administrator.x2picturetransliteration.Home.Activity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.x2picturetransliteration.Base.BaseActivity;
import com.example.administrator.x2picturetransliteration.Base.BasePresenter;
import com.example.administrator.x2picturetransliteration.Constants;
import com.example.administrator.x2picturetransliteration.Home.Presenter.Activity.SignInPresenter;
import com.example.administrator.x2picturetransliteration.R;
import com.example.administrator.x2picturetransliteration.Util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 其他登录
 * Created by Administrator on 2019/8/16.
 */

public class OtherActivity extends BaseActivity{

    @BindView(R.id.TelephoneEdit)TextView TelephoneEdit; //账号
    @BindView(R.id.PwEdit)TextView PwEdit; //密码

    @BindView(R.id.AImg)ImageView AImg; //用户协议按钮

    @BindView(R.id.gsText)TextView gsText;

    private SignInPresenter mSignInPresenter;

    @Override
    public int intiLayout() {
        return R.layout.home_activity_other;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String gsName = Constants.getConstants().getmAppDataBean().getCompanyName();

        if (gsName!=null)gsText.setText(gsName);

        mSignInPresenter= new SignInPresenter(this,mCompositeSubscriptions);
    }

    /** 返回 */
    @OnClick(R.id.ReturnView)
    public void ReturnViewClick(){

        finish();
    }

    /** 忘记密码 */
    @OnClick(R.id.ForgetPwEdit)
    public void ForgetPwEditClick(){

        ForgetActivity.startForgetActivity(this,null);
    }

    /** 登录 */
    @OnClick(R.id.SignInText)
    public void SignInTextClick(){

        if (!AJudge){

            new ToastUtil(this).getToast(false,"请同意用户协议").show();
            return;
        }

        if ("".equals(TelephoneEdit.getText() + "")){

            new ToastUtil(this).getToast(false,"请输入手机号").show();
            return;

        }else if ("".equals(PwEdit.getText() + "")){

            new ToastUtil(this).getToast(false,"请输入密码").show();
            return;
        }

        Intent intent = this.getIntent();
        intent.putExtra("Telephone",(TelephoneEdit.getText() + ""));
        intent.putExtra("Pwd",(PwEdit.getText() + ""));
        this.setResult(Activity.RESULT_OK, intent);//返回页面
        this.finish();


    }

    /** 同意用户协议 */
    private boolean AJudge = false;
    @OnClick(R.id.A)
    public void AClick(){

        if (AJudge){

            AImg.setImageResource(R.mipmap.home_check0);

        }else {

            AImg.setImageResource(R.mipmap.home_check1);
        }

        AJudge = !AJudge;
    }

    /** 用户协议 */
    @OnClick(R.id.B)
    public void BClick(){

        mSignInPresenter.Agreement("1",new BasePresenter.Callback() {
            @Override
            public void getData(Object data) {

                AgreementActivity.startAgreementActivity(OtherActivity.this,"用户协议",data + "");
            }
        });
    }

    /** 隐私政策 */
    @OnClick(R.id.C)
    public void CClick(){

        mSignInPresenter.Agreement("2",new BasePresenter.Callback() {
            @Override
            public void getData(Object data) {

                AgreementActivity.startAgreementActivity(OtherActivity.this,"隐私政策",data + "");
            }
        });
    }
}
